from public_way import public_invoking
from utils.times_tool.time_control import now_time


class StarrocksSynchronization:

    """
    Starrocks数据同步服务
    """

    def startrocks_test_server(self,id):

        star_sql = f"SELECT ErpId, ListingPrice, OrderSourceID, OrderSourceSKU FROM `aml_amazon_product_base` WHERE OrderSourceID IN ({id}) AND AddTime < '2023-03-06 23：59：59';"
        cold_sql = f"SELECT ErpId, ListingPrice, OrderSourceID, OrderSourceSKU FROM `aml_amazon_product_base_dep84` WHERE OrderSourceID IN ({id}) AND AddTime < '2023-03-06 23：59：59'"
        error_lis = []
        res_startrocks = public_invoking().startrocks_db(star_sql)
        res_cold = public_invoking().cold_db(cold_sql)

        for n in res_startrocks:
            n["ListingPrice"] = float(n["ListingPrice"])

        for i in res_cold:
            i["ListingPrice"] = float(i["ListingPrice"])
            if i not in res_startrocks:
                # print(i)
                error_lis.append(i)

        report = f"执行时间:{now_time()}    \n" \
                 f"同步Startrocks数据库服务验证  \n" \
                 f"OrderSourceID：{id}   \n" \
                 f"Stratrocks检测数据{len(res_startrocks)}条 \n" \
                 f"冷数据库检测数据{len(res_cold)}条 \n" \
                 f"发现异常数据{len(error_lis)}条  \n" \
                 f"异常明细:    \n" \
                 f"{error_lis}"
        return report


if __name__ == '__main__':

    # startrocks同步验证
    id = "11702,15319"
    res = StarrocksSynchronization().startrocks_test_server(id)
    print(res)

